home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 November: Tool Chest / Dev.CD Nov 94.toast / Sample Code / Snippets / Toolbox / GetDragHiliteColor / GetDragHilite.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-09-11  |  3.3 KB  |  115 lines  |  [TEXT/MPS ]

  1. #include <Windows.h>
  2. #include <QuickDraw.h>
  3.  
  4. #define wTitleBarColor    4
  5. #define wTingeLight        11
  6. #define wTingeDark        12
  7.  
  8.  
  9. /*-------------------------------------------------------------------------------------
  10.  
  11. BlendValues
  12.  
  13.     Blend two color values by 27%.  Be careful of overflow when multiplying
  14.     a negative number.  Output should be light + 27% of difference between light
  15.     and dark.
  16.  
  17. */
  18. unsigned short BlendValues(short lightValue, short darkValue)
  19. {
  20.     register short blender;
  21.  
  22.     blender = darkValue - lightValue;
  23.  
  24.     if ((unsigned long)lightValue > (unsigned long)darkValue)
  25.         blender = -blender;                        // flip if subtraction would overflow
  26.  
  27.     blender = (unsigned short)((unsigned short)blender * .27);
  28.                                                 // 27% percent multiply
  29.  
  30.     if ((unsigned long)lightValue > (unsigned long)darkValue)
  31.         blender = -blender;                        // flip it back if it was flipped the
  32.                                                 // first time.
  33.  
  34.     return ((unsigned short)(lightValue + blender));
  35. }
  36.  
  37.  
  38. /*-------------------------------------------------------------------------------------
  39.  
  40. SetupDragHiliteColor
  41.  
  42.     Set the fore color to the color used by the Drag Manager to hilite regions.
  43.     
  44. */
  45. void SetupDragHiliteColor(WindowPtr targetWindow)
  46. {
  47.     RGBColor windowRGB, lightRGB, darkRGB;
  48.     AuxWinHandle auxHandle;                        // the default AuxWindow data
  49.     CTabHandle winColorTable;                        // the window color table
  50.     short i, j;                                    // for our color table search
  51.  
  52.     windowRGB.red = 0x8000;                        // Default to 50% gray.
  53.     windowRGB.green = 0x8000;
  54.     windowRGB.blue = 0x8000;
  55.  
  56.     // If we're using a window which uses System 7's 3D colors
  57.     // then set the hilite color to a tinge for that window.
  58.  
  59.     GetAuxWin(targetWindow, &auxHandle);
  60.  
  61.     // do we have an aux window handle ?
  62.     if (auxHandle != nil) {
  63.         winColorTable = (**auxHandle).awCTable;
  64.  
  65.         // do we have a system 7 sized window color table?
  66.         if ((**winColorTable).ctSize > wTitleBarColor) {
  67.             
  68.             // yes, now search for the tinge color, start at the end
  69.             // because our tinge colors are usually last in the list.
  70.             for (i = (**winColorTable).ctSize; i > 0; i--) {
  71.                 if ((**winColorTable).ctTable[i].value == wTingeLight) {
  72.  
  73.                     // light tinge found, set the window color to it
  74.                     // in case we can't find the dark tinge.
  75.                     lightRGB = (**winColorTable).ctTable[i].rgb;
  76.  
  77.                     windowRGB.red = lightRGB.red;
  78.                     windowRGB.green = lightRGB.green;
  79.                     windowRGB.blue = lightRGB.blue;
  80.  
  81.                     // we now need the wTingeDark entry to perform a blend.
  82.                     // again, search from the end
  83.                     for (j = (**winColorTable).ctSize; j > 0; j--)
  84.                         if ((**winColorTable).ctTable[j].value == wTingeDark) {
  85.                             // dark tinge found.  now do the blend
  86.  
  87.                             darkRGB = (**winColorTable).ctTable[j].rgb;
  88.  
  89.                             windowRGB.red = BlendValues((short)lightRGB.red, (short)darkRGB.red);
  90.                             windowRGB.green = BlendValues((short)lightRGB.green, (short)darkRGB.green);
  91.                             windowRGB.blue = BlendValues((short)lightRGB.blue, (short)darkRGB.blue);
  92.  
  93.                             // if the Color control panel was set to "Black and White", it makes the
  94.                             // tinge colors black and black.  Use gray in this case
  95.  
  96.                             if ((windowRGB.red | windowRGB.green | windowRGB.blue) == 0) {
  97.                                 windowRGB.red = 0x8000;
  98.                                 windowRGB.green = 0x8000;
  99.                                 windowRGB.blue = 0x8000;
  100.                             }
  101.  
  102.                             j = 0;                // bail from inner loop
  103.                         }
  104.  
  105.                     i = 0;                        // bail from outer loop
  106.                 }
  107.             }
  108.         }
  109.     }
  110.  
  111.     RGBForeColor(&windowRGB);        // finally, set it
  112. }
  113.  
  114.  
  115.